from azure.devops.connection import Connection
from msrest.authentication import BasicAuthentication

# Azure DevOps组织URL
organization_url = 'https://dev.azure.com/HKWebApp'

# Azure DevOps个人访问令牌 (PAT) - 用于身份验证
pat = 'rohvxi4cveemyk2ttapc5whjn22ohjfmeabdds7xh4nn7ls7uctq'

# 连接到Azure DevOps服务
credentials = BasicAuthentication('', pat)
connection = Connection(base_url=organization_url, creds=credentials)

# 获取项目客户端
project_client = connection.clients.get_project_client()

# 获取所有项目
projects = project_client.get_projects()

# 遍历项目并输出项目ID和名称
for project in projects:
    project_id = project.id
    project_name = project.name

    print(f'Project ID: {project_id}')
    print(f'Project Name: {project_name}')
    print('------------------------')